import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class OrdersInput(BaseOctopusCloud):
    _CLICK_CHANNEL = By.XPATH, '//*[@class="el-input__inner"]'
    _CHOOSE_CHANNEL = By.XPATH, '//*[text()="学员测试专用"]'
    _CLICK_TEXT = By.XPATH, '//*[@class="el-textarea__inner"]'
    _CLICK_IDENTIFY = By.XPATH, '//*[text()="识别订单信息"]'
    _CLICK_GOODS = By.XPATH, '(//*[@class="el-input__inner"])[6]'
    _CHOOSE_GOODS = By.XPATH, '//*[text()="大大泡泡糖（测吧测试1八爪云仓库1）"]'
    _CHOOSE_GOODS_CLASS = By.XPATH, '//*[text()="颗(规格编码:skuGLNFRIF9)"]'
    _CLICK_NUMS = By.XPATH, '(//*[@class="el-input__inner"])[7]'
    _CLICK_SUBMIT = By.XPATH, '//*[text()="提交"]'

    @allure.step("完成创建订单录入操作")
    def orders_input(self, message, num):
        # 点击选择渠道
        self.find_ele(*self._CLICK_CHANNEL).click()
        # 选择渠道
        time.sleep(2)
        self.find_ele(*self._CHOOSE_CHANNEL).click()
        # 点击文本框
        self.find_ele(*self._CLICK_TEXT).click()
        self.find_ele(*self._CLICK_TEXT).send_keys(message)
        # 点击识别
        self.find_ele(*self._CLICK_IDENTIFY).click()
        # 点击商品
        time.sleep(2)
        self.find_ele(By.XPATH, '(//*[@class="el-input__inner"])[2]').click()
        time.sleep(2)
        self.find_ele(*self._CLICK_GOODS).click()
        # 选择商品
        time.sleep(3)
        self.find_ele(*self._CHOOSE_GOODS).click()
        self.find_ele(*self._CHOOSE_GOODS_CLASS).click()
        # 点击数量
        time.sleep(3)
        self.find_ele(*self._CLICK_NUMS).click()
        self.find_ele(*self._CLICK_NUMS).send_keys(num)
        # 点击提交
        self.find_ele(*self._CLICK_SUBMIT).click()
        logger.info("完成创建订单录入操作")

        from bazhuayun.page.orders_list_page import OrdersListPage
        return OrdersListPage(self.driver)
